//
//  LoginFadeInOutView.m
//  DeepBreathing
//
//  Created by rimi on 15/12/19.
//  Copyright © 2015年 rimi. All rights reserved.
//

#import "LoginFadeInOutView.h"

@interface LoginFadeInOutView ()

@property(nonatomic,strong)NSTimer* timer;

@property(nonatomic,strong)UIImageView *backImage;
@property(nonatomic,strong)UIImageView *moveimage;

@end

@implementation LoginFadeInOutView
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self createImageView];
    }
    return self;
}

-(void)createImageView{
    
    
    
    
    _timer =  [NSTimer scheduledTimerWithTimeInterval:3
                                               target:self
                                             selector:@selector(show)
                                             userInfo:nil
                                              repeats:YES];
    
    _backImage = [[UIImageView alloc]initWithFrame:self.frame];
    
    _backImage.image = [UIImage imageNamed:@"defeat"];
  
    [self addSubview:_backImage];
    
    
    _moveimage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(self.frame), CGRectGetMaxY(self.frame)/3 + 100)];
    
    _moveimage.image = [UIImage imageNamed:@"defeat_03"];
    
    _moveimage.tag = 101;
    
    [self addSubview:_moveimage];
    
}

-(void)show{
    
    UIImageView *imageView = (UIImageView *)[self viewWithTag:101];
    
    [UIView beginAnimations:@"show" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    
    [UIView setAnimationDuration:1.0];
    
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(FadeOut)];
    imageView.alpha = 0.0;
    
    [UIView commitAnimations];
    
}
-(void)FadeOut{
    UIImageView *imageView = (UIImageView *)[self viewWithTag:101];
    
    [UIView beginAnimations:@"FadeOut" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
    [UIView setAnimationDuration:1.0];
    
    [UIView setAnimationDelay:1.0];
    
    imageView.alpha = 1.0;
    
    [UIView commitAnimations];
    
    
    
    
}

@end
